home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1997 December / PC Pro December 1997 CD-Rom coverdisc.iso / symantec / dbAnywh / JAVA.BIN / CLASSES.ZIP / sun / tools / tree / ConditionalExpression.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-12-14  |  4.9 KB  |  162 lines

  1. package sun.tools.tree;
  2.  
  3. import java.io.PrintStream;
  4. import java.util.Hashtable;
  5. import sun.tools.asm.Assembler;
  6. import sun.tools.asm.Label;
  7. import sun.tools.java.ClassNotFound;
  8. import sun.tools.java.CompilerError;
  9. import sun.tools.java.Constants;
  10. import sun.tools.java.Environment;
  11. import sun.tools.java.Type;
  12.  
  13. public class ConditionalExpression extends BinaryExpression {
  14.    Expression cond;
  15.  
  16.    public ConditionalExpression(int var1, Expression var2, Expression var3, Expression var4) {
  17.       super(13, var1, Type.tError, var3, var4);
  18.       this.cond = var2;
  19.    }
  20.  
  21.    public Expression order() {
  22.       if (((Expression)this).precedence() > this.cond.precedence()) {
  23.          UnaryExpression var1 = (UnaryExpression)this.cond;
  24.          this.cond = var1.right;
  25.          var1.right = this.order();
  26.          return var1;
  27.       } else {
  28.          return this;
  29.       }
  30.    }
  31.  
  32.    public long checkValue(Environment var1, Context var2, long var3, Hashtable var5) {
  33.       try {
  34.          ConditionVars var6 = this.cond.checkCondition(var1, var2, var3, var5);
  35.          var3 = super.left.checkValue(var1, var2, var6.vsTrue, var5) & super.right.checkValue(var1, var2, var6.vsFalse, var5);
  36.          this.cond = ((Node)this).convert(var1, var2, Type.tBoolean, this.cond);
  37.          int var7 = super.left.type.getTypeMask() | super.right.type.getTypeMask();
  38.          if ((var7 & 8192) != 0) {
  39.             super.type = Type.tError;
  40.             return var3;
  41.          } else {
  42.             if (super.left.type.equals(super.right.type)) {
  43.                super.type = super.left.type;
  44.             } else if ((var7 & 128) != 0) {
  45.                super.type = Type.tDouble;
  46.             } else if ((var7 & 64) != 0) {
  47.                super.type = Type.tFloat;
  48.             } else if ((var7 & 32) != 0) {
  49.                super.type = Type.tLong;
  50.             } else if ((var7 & 1792) != 0) {
  51.                super.type = var1.implicitCast(super.right.type, super.left.type) ? super.left.type : super.right.type;
  52.             } else if ((var7 & 4) != 0 && super.left.fitsType(var1, Type.tChar) && super.right.fitsType(var1, Type.tChar)) {
  53.                super.type = Type.tChar;
  54.             } else if ((var7 & 8) != 0 && super.left.fitsType(var1, Type.tShort) && super.right.fitsType(var1, Type.tShort)) {
  55.                super.type = Type.tShort;
  56.             } else if ((var7 & 2) != 0 && super.left.fitsType(var1, Type.tByte) && super.right.fitsType(var1, Type.tByte)) {
  57.                super.type = Type.tByte;
  58.             } else {
  59.                super.type = Type.tInt;
  60.             }
  61.  
  62.             super.left = ((Node)this).convert(var1, var2, super.type, super.left);
  63.             super.right = ((Node)this).convert(var1, var2, super.type, super.right);
  64.             return var3;
  65.          }
  66.       } catch (ClassNotFound var8) {
  67.          throw new CompilerError(var8);
  68.       }
  69.    }
  70.  
  71.    public long check(Environment var1, Context var2, long var3, Hashtable var5) {
  72.       var3 = this.cond.checkValue(var1, var2, var3, var5);
  73.       this.cond = ((Node)this).convert(var1, var2, Type.tBoolean, this.cond);
  74.       return super.left.check(var1, var2, var3, var5) & super.right.check(var1, var2, var3, var5);
  75.    }
  76.  
  77.    Expression simplify() {
  78.       if (this.cond.equals(true)) {
  79.          return super.left;
  80.       } else {
  81.          return (Expression)(this.cond.equals(false) ? super.right : this);
  82.       }
  83.    }
  84.  
  85.    public Expression inline(Environment var1, Context var2) {
  86.       super.left = super.left.inline(var1, var2);
  87.       super.right = super.right.inline(var1, var2);
  88.       if (super.left == null && super.right == null) {
  89.          return this.cond.inline(var1, var2);
  90.       } else {
  91.          if (super.left == null) {
  92.             super.left = super.right;
  93.             super.right = null;
  94.             this.cond = new NotExpression(super.where, this.cond);
  95.          }
  96.  
  97.          this.cond = this.cond.inlineValue(var1, var2);
  98.          return this.simplify();
  99.       }
  100.    }
  101.  
  102.    public Expression inlineValue(Environment var1, Context var2) {
  103.       this.cond = this.cond.inlineValue(var1, var2);
  104.       super.left = super.left.inlineValue(var1, var2);
  105.       super.right = super.right.inlineValue(var1, var2);
  106.       return this.simplify();
  107.    }
  108.  
  109.    public int costInline(int var1) {
  110.       return 1 + this.cond.costInline(var1) + super.left.costInline(var1) + super.right.costInline(var1);
  111.    }
  112.  
  113.    public Expression copyInline(Context var1) {
  114.       ConditionalExpression var2 = (ConditionalExpression)((Node)this).clone();
  115.       var2.cond = this.cond.copyInline(var1);
  116.       var2.left = super.left.copyInline(var1);
  117.       var2.right = super.right.copyInline(var1);
  118.       return var2;
  119.    }
  120.  
  121.    public void codeValue(Environment var1, Context var2, Assembler var3) {
  122.       Label var4 = new Label();
  123.       Label var5 = new Label();
  124.       this.cond.codeBranch(var1, var2, var3, var4, false);
  125.       super.left.codeValue(var1, var2, var3);
  126.       var3.add(super.where, 167, var5);
  127.       var3.add(var4);
  128.       super.right.codeValue(var1, var2, var3);
  129.       var3.add(var5);
  130.    }
  131.  
  132.    public void code(Environment var1, Context var2, Assembler var3) {
  133.       Label var4 = new Label();
  134.       this.cond.codeBranch(var1, var2, var3, var4, false);
  135.       super.left.code(var1, var2, var3);
  136.       if (super.right != null) {
  137.          Label var5 = new Label();
  138.          var3.add(super.where, 167, var5);
  139.          var3.add(var4);
  140.          super.right.code(var1, var2, var3);
  141.          var3.add(var5);
  142.       } else {
  143.          var3.add(var4);
  144.       }
  145.    }
  146.  
  147.    public void print(PrintStream var1) {
  148.       var1.print("(" + Constants.opNames[super.op] + " ");
  149.       this.cond.print(var1);
  150.       var1.print(" ");
  151.       super.left.print(var1);
  152.       var1.print(" ");
  153.       if (super.right != null) {
  154.          super.right.print(var1);
  155.       } else {
  156.          var1.print("<null>");
  157.       }
  158.  
  159.       var1.print(")");
  160.    }
  161. }
  162.